﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SqlSugarFirst
{
    public class SugarFactory
    {
        private static string strConnectionString = string.Empty;

        /// <summary>
        /// 数据库访问对象
        /// </summary>
        private static SqlSugarClient db = null;

        //私有构造函数，禁止实例化
        private SugarFactory()
        {
        }

        /// <summary>
        /// 初始化SqlSugarClient
        /// </summary>
        /// <returns>返回SqlSugarClient对象</returns>
        public static SqlSugarClient GetInstance(string connid, bool action)
        {
            int DbType = 0;
            switch (connid)
            {
                case "SAE_OFN":
                    DbType = 0;
                    /* action  true： Production 生产环境库；  false： Test测试环境库*/
                    if (action)
                        strConnectionString = "Host=DBSvr02.cloudlight.com.hk;User Id=module_web;Password=cl_module_web56;Database=SAE_OFN;Respect Binary Flags=False;Default Command Timeout=120;Allow User Variables=True";
                    else
                        strConnectionString = "Host=10.10.103.163;User Id=module_web;Password=Abc@2022;Database=SAE_OFN;Respect Binary Flags=False;Default Command Timeout=120;Allow User Variables=True";
                    break;
                case "OUSB":
                    DbType = 3;
                    if (action)
                        strConnectionString = "Data Source= (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =DBSvr01.cloudlight.com.hk)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =PRODDB01)));User ID=ousb;Password=clousb65";
                    else
                        strConnectionString = "Data Source= (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =10.10.101.79)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =PRODDB01)));User ID=ousb;Password=ousb20221123";
                    break;
                case "LABEL":
                    DbType = 3;
                    if (action)
                        strConnectionString = "Data Source= (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = DBSvr01.cloudlight.com.hk)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = LABELING))) ; User ID=label;Password=lb2019";
                    else
                        strConnectionString = "Data Source= (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =10.10.101.79)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =LABELING)));User ID=label;Password=label20221123";
                    break;
                /*localhost 本地*/
                case "Test_Demo":
                    DbType = 1;
                    strConnectionString = "Server=DESKTOP-9GRFFRR;database=Test_Demo;Trusted_Connection=True;MultipleActiveResultSets=True;";
                    break;
                case "TEXT":
                    DbType = 1;
                    strConnectionString = "Server=30-0001-21708\\MSSQLSERVER02;database=TEXT;Trusted_Connection=True;MultipleActiveResultSets=True;";
                    break;
                case "TEST":
                    DbType = 3;
                    strConnectionString = "Data Source= (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =localhost)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME =ORCL)));User ID=TEST;Password=TEST;";
                    break;
            }

            db = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = strConnectionString,
                DbType = (DbType)DbType,
                IsAutoCloseConnection = true
            });
            return db;
        }

    }
}
